<!--
 * @Author: 'yangyuhang1203' '2621131059@qq.com'
 * @Date: 2025-09-10 14:17:31
 * @LastEditors: 'yangyuhang1203' '2621131059@qq.com'
 * @LastEditTime: 2025-09-10 14:28:10
 * @FilePath: \企业级\前端\js\js事件绑定.html
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="button" onclick="on(1)" value="事件绑定1" id="btn1">
    <input type="button" value="事件绑定2" id="btn2">
    <script>
        // 绑定方式一 使用标签内部的事件属性
        function on(a){
            alert("按钮"+a+"被点击了...");
        }
        // 绑定方式二 使用element元素内的属性
        // var oBtn = document.getElementById("byn2");
        document.getElementById("btn2").onclick = function(){
        alert("按钮2被点击了...");
        };
    </script>
</body>
</html>